package com.ruoyi.web.domain.stock;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.pojo.request.stock.StorageAddReq;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.Map;

/**
 * 入库明细对象 storage
 * 
 * @author zq
 * @date 2024-01-06
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Storage
{

    /** id */
    private Long id;

    /** 产品名称 */
    @Excel(name = "产品名称")
    private String product;

    /** 产品类型 */
    @Excel(name = "产品类型")
    private String type;

    /** 数量 */
    @Excel(name = "数量")
    private Float number;

    /** 单位 */
    @Excel(name = "单位")
    private String unit;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /** 用户ID */
    private Long userId;

    /** 库存ID */
    @Excel(name = "库存ID")
    private String stockId;
    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    @ApiModelProperty("开始时间 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startTime;
    @ApiModelProperty("结束时间 yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date endTime;


    /** 创建者 */
    private String createBy;

    /** 备注 */
    private String remark;
    /** 更新者 */
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date updateTime;
    /** 请求参数 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Map<String, Object> params;
    public static Storage toStorage(StorageAddReq storageAddReq) {
        if (storageAddReq == null) {
            return null;
        }
        Storage storage = new Storage();
        storage.setProduct(storageAddReq.getProduct());
        storage.setType(storageAddReq.getType());
        storage.setNumber(storageAddReq.getNumber());
        storage.setUnit(storageAddReq.getUnit());
        storage.setStockId(storageAddReq.getStockId());
        storage.setCreateTime(storageAddReq.getCreateTime());
        storage.setCreateBy(SecurityUtils.getUsername());
        // Not mapped Storage fields:
        // id
        // delFlag
        // userId
        return storage;
    }
}
